using Microsoft.Office.Interop.Excel;
using OrderSystem.SystemFramework;
using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;

namespace OrderSystem.FormatOutput
{
    public class ExcelOperationFlowcard
	{
		private _Application app;

		private _Workbook workBook;

		private _Worksheet workSheet;

		private Range range;

		private object missing = Missing.Value;

		private string _startupPath = null;

		public ExcelOperationFlowcard(string startupPath)
		{
			this._startupPath = startupPath;
			if (this._startupPath.Substring(this._startupPath.Length - 1, 1) != "\\")
			{
				this._startupPath += "\\";
			}
		}

		private void OpenExcel(string templetFile)
		{
			if (templetFile == null)
			{
				throw new ArgumentException("你指定的参数：templetFile 为空", "templetFile");
			}
			if (!File.Exists(templetFile))
			{
				throw new ArgumentException("你指定的参数：templetFile Excel模板文件不存在", "templetFile");
			}
            app = new ApplicationClass
            {
                Visible = true
            };
            this.workBook = this.app.Workbooks.Open(templetFile, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing, this.missing);
			this.workSheet = (_Worksheet)this.workBook.Worksheets[1];
		}

		public void MakeOrderDataToExcel(string templetFile, DataSet dsItem, string sFlowcardCode, string sCompanyName, string sProjectName, string sSpeakForDate, string sDeliveryDate, string sLinkman, string sPhone, string sAddress, string sRemark, string sOperatorName, string sSalesperson, string sYaoqiu)
		{
			this.OpenExcel(templetFile);
			string defaultVersionOfOutType = AppSettings.GetDefaultVersionOfOutType("flowcard");
			if (defaultVersionOfOutType == "1")
			{
				this.MakeOrderDataToExcel_1(dsItem, sFlowcardCode, sCompanyName, sProjectName, sSpeakForDate, sDeliveryDate, sLinkman, sPhone, sAddress, sRemark, sOperatorName, sSalesperson, sYaoqiu, 40, 21);
			}
			if (defaultVersionOfOutType == "4")
			{
				this.MakeOrderDataToExcel_4(dsItem, sFlowcardCode, sCompanyName, sProjectName, sSpeakForDate, sDeliveryDate, sLinkman, sPhone, sAddress, sRemark, sOperatorName, sSalesperson, sYaoqiu, 40, 21);
			}
		}

		private void MakeOrderDataToExcel_1(DataSet dsOrderItem, string sFlowcardCode, string sCompanyName, string sProjectName, string sSpeakForDate, string sDeliveryDate, string sLinkman, string sPhone, string sAddress, string sRemark, string sOperatorName, string sSalesperson, string sYaoqiu, int nRowCountOfPage, int nRowHight)
		{
			int count = dsOrderItem.Tables[0].Rows.Count;
			try
			{
				bool flag = true;
				int num = 1;
				int num2 = 7;
				int num3 = 0;
				decimal d = 0m;
				this.workSheet = (Worksheet)workBook.Worksheets[this.workBook.Worksheets.Count];
				this.range = (Range)this.workSheet.Rows[8, this.missing];
				int i;
				for (i = 1; i < nRowCountOfPage; i++)
				{
					this.range.Insert(-4121, 1);
				}
				this.range = (Range)this.workSheet.Rows[nRowCountOfPage + 7, this.missing];
				for (i = 1; i < nRowCountOfPage; i++)
				{
					Range range = (Range)this.workSheet.Rows[i + 7, this.missing];
					this.range.Copy(range);
				}
				((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
				this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
				this.workSheet.Activate();
				this.workSheet.Cells[3, 12]= sFlowcardCode;
				this.workSheet.Cells[4, 1]=string.Concat(new string[]
				{
					"订货单位:",
					sCompanyName,
					"(",
					sProjectName,
					")    订货时间:",
					sSpeakForDate,
					"  交货日期: ",
					sDeliveryDate,
					"    联系人:",
					sLinkman
				});
				this.workSheet.Cells[5, 1]=string.Concat(new string[]
				{
					"联系电话:",
					sPhone,
					"    地址:",
					sAddress,
					"    备注:",
					sRemark
				});
				this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
				this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
				this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
				this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
				num2++;
				this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 2], this.workSheet.Cells[num2, 16]);
				this.range.ClearContents();
				this.range.MergeCells=true;
				this.workSheet.Cells[num2, 1]= "【类型】";
				this.workSheet.Cells[num2, 2]= dsOrderItem.Tables[0].Rows[0]["产品类型"].ToString();
				for (i = 0; i < count; i++)
				{
					if (flag)
					{
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[3, 12]= sFlowcardCode;
							this.workSheet.Cells[4, 1]=string.Concat(new string[]
							{
								"订货单位:",
								sCompanyName,
								"(",
								sProjectName,
								")    订货时间:",
								sSpeakForDate,
								"  交货日期: ",
								sDeliveryDate,
								"    联系人:",
								sLinkman
							});
							this.workSheet.Cells[5, 1]=string.Concat(new string[]
							{
								"联系电话:",
								sPhone,
								"    地址:",
								sAddress,
								"    备注:",
								sRemark
							});
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
							this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
							this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
							num2 = 8;
						}
					}
					decimal d2 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["宽"]);
					decimal d3 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["高"]);
					int num4 = Convert.ToInt32(dsOrderItem.Tables[0].Rows[i]["产品数量"]);
					decimal num5 = d2 * d3 / 1000000m;
					num5 *= num4;
					num3 += num4;
					d += num5;
					if (flag)
					{
						this.workSheet.Cells[num2, 1]= dsOrderItem.Tables[0].Rows[i]["产品编号"].ToString();
						string text = dsOrderItem.Tables[0].Rows[i]["宽(短边)"].ToString();
						string text2 = dsOrderItem.Tables[0].Rows[i]["高(短边)"].ToString();
						this.workSheet.Cells[num2, 2]= d2.ToString() + ((text == "") ? "" : ("/" + text));
						this.workSheet.Cells[num2, 3]= d3.ToString() + ((text2 == "") ? "" : ("/" + text2));
						this.workSheet.Cells[num2, 4]= num4.ToString();
						this.workSheet.Cells[num2, 5]= num5.ToString("F3");
						this.workSheet.Cells[num2, 6]= Convert.ToDouble(dsOrderItem.Tables[0].Rows[i]["价格"].ToString());
						this.workSheet.Cells[num2, 7]= dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() + ((dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() != "" && dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString() != "") ? ("/" + dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString()) : dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString());
						this.workSheet.Cells[num2, 8]= dsOrderItem.Tables[0].Rows[i]["产品ID"].ToString();
						flag = false;
					}
					else
					{
						this.workSheet.Cells[num2, 10]= dsOrderItem.Tables[0].Rows[i]["产品编号"].ToString();
						string text = dsOrderItem.Tables[0].Rows[i]["宽(短边)"].ToString();
						string text3 = dsOrderItem.Tables[0].Rows[i]["高(短边)"].ToString();
						this.workSheet.Cells[num2, 11]= d2.ToString() + ((text == "") ? "" : ("/" + text));
						this.workSheet.Cells[num2, 12]= d3.ToString() + ((text3 == "") ? "" : ("/" + text3));
						this.workSheet.Cells[num2, 13]= num4.ToString();
						this.workSheet.Cells[num2, 14]= num5.ToString("F3");
						this.workSheet.Cells[num2, 15]= Convert.ToDouble(dsOrderItem.Tables[0].Rows[i]["产品价格"].ToString());
						this.workSheet.Cells[num2, 16]= dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() + ((dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() != "" && dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString() != "") ? ("/" + dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString()) : dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString());
						this.workSheet.Cells[num2, 17]= dsOrderItem.Tables[0].Rows[i]["产品ID"].ToString();
						flag = true;
					}
					string a = dsOrderItem.Tables[0].Rows[i][1].ToString();
					if (i == count - 1)
					{
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[3, 12]= sFlowcardCode;
							this.workSheet.Cells[4, 1]=string.Concat(new string[]
							{
								"订货单位:",
								sCompanyName,
								"(",
								sProjectName,
								")    订货时间:",
								sSpeakForDate,
								"  交货日期: ",
								sDeliveryDate,
								"    联系人:",
								sLinkman
							});
							this.workSheet.Cells[5, 1]=string.Concat(new string[]
							{
								"联系电话:",
								sPhone,
								"    地址:",
								sAddress,
								"    备注:",
								sRemark
							});
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
							this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
							this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
							num2 = 8;
						}
						this.workSheet.Cells[num2, 1]= "·";
						this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 3], this.workSheet.Cells[num2, 16]);
						this.range.ClearContents();
						this.range.MergeCells=true;
						this.workSheet.Cells[num2, 2]= " 小计 ";
						this.workSheet.Cells[num2, 3]= "数量：" + num3.ToString()+ ";   面积：" + d.ToString("F3");
						num3 = 0;
						d = 0m;
						flag = true;
					}
					else if (a != dsOrderItem.Tables[0].Rows[i + 1][1].ToString())
					{
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[3, 12]= sFlowcardCode;
							this.workSheet.Cells[4, 1]=string.Concat(new string[]
							{
								"订货单位:",
								sCompanyName,
								"(",
								sProjectName,
								")    订货时间:",
								sSpeakForDate,
								"  交货日期: ",
								sDeliveryDate,
								"    联系人:",
								sLinkman
							});
							this.workSheet.Cells[5, 1]=string.Concat(new string[]
							{
								"联系电话:",
								sPhone,
								"    地址:",
								sAddress,
								"    备注:",
								sRemark
							});
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
							this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
							this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
							num2 = 8;
						}
						this.workSheet.Cells[num2, 1]= "·";
						this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 3], this.workSheet.Cells[num2, 16]);
						this.range.ClearContents();
						this.range.MergeCells=true;
						this.workSheet.Cells[num2, 2]= " 小计 ";
						this.workSheet.Cells[num2, 3]= "数量：" + num3.ToString() + ";   面积：" + d.ToString("F3");
						num3 = 0;
						d = 0m;
						flag = true;
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[3, 12]= sFlowcardCode;
							this.workSheet.Cells[4, 1]=string.Concat(new string[]
							{
								"订货单位:",
								sCompanyName,
								"(",
								sProjectName,
								")    订货时间:",
								sSpeakForDate,
								"  交货日期: ",
								sDeliveryDate,
								"    联系人:",
								sLinkman
							});
							this.workSheet.Cells[5, 1]=string.Concat(new string[]
							{
								"联系电话:",
								sPhone,
								"    地址:",
								sAddress,
								"    备注:",
								sRemark
							});
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
							this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
							this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
							num2 = 8;
						}
						this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 2], this.workSheet.Cells[num2, 16]);
						this.range.ClearContents();
						this.range.MergeCells=true;
						this.workSheet.Cells[num2, 1]= "【类型】";
						this.workSheet.Cells[num2, 2]= dsOrderItem.Tables[0].Rows[i + 1]["产品类型"].ToString();
					}
				}
				num2++;
				if (num2 > nRowCountOfPage + 7)
				{
					num++;
					((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
					this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
					this.workSheet.Activate();
					this.workSheet.Cells[3, 12]= sFlowcardCode;
					this.workSheet.Cells[4, 1]=string.Concat(new string[]
					{
						"订货单位:",
						sCompanyName,
						"(",
						sProjectName,
						")    订货时间:",
						sSpeakForDate,
						"  交货日期: ",
						sDeliveryDate,
						"    联系人:",
						sLinkman
					});
					this.workSheet.Cells[5, 1]=string.Concat(new string[]
					{
						"联系电话:",
						sPhone,
						"    地址:",
						sAddress,
						"    备注:",
						sRemark
					});
					this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
					this.range.Value2=this.range.Text.ToString().Replace("?", sOperatorName);
					this.workSheet.Cells[nRowCountOfPage + 7 + 1, 2]= sYaoqiu;
					this.workSheet.Name="页-" + (this.workSheet.Index - 1).ToString();
					num2 = 8;
				}
				decimal d4 = 0m;
				decimal num6 = 0m;
				for (i = 0; i < dsOrderItem.Tables[0].Rows.Count; i++)
				{
					decimal d2 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["宽"]);
					decimal d3 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["高"]);
					int num4 = Convert.ToInt32(dsOrderItem.Tables[0].Rows[i]["产品数量"]);
					decimal d5 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["产品价格"]);
					decimal num5 = Convert.ToDecimal((d2 * d3 / 1000000m).ToString("F4")) * num4;
					d4 += num5 * d5;
				}
				for (i = 0; i < dsOrderItem.Tables[1].Rows.Count; i++)
				{
					decimal d6 = Convert.ToDecimal(dsOrderItem.Tables[1].Rows[i]["数量"]);
					decimal d5 = Convert.ToDecimal(dsOrderItem.Tables[1].Rows[i]["单价"]);
					num6 += d6 * d5;
				}
				this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 3], this.workSheet.Cells[num2, 16]);
				this.range.ClearContents();
				this.range.MergeCells=true;
				this.workSheet.Cells[num2, 1]= "·";
				this.workSheet.Cells[num2, 2]= "合计";
				this.workSheet.Cells[num2, 3]= string.Concat(new string[]
				{
					"面积金额：",
					d4.ToString("F2"),
					"； 工艺金额：",
					num6.ToString("F2"),
					"； 总金额为：",
					(d4 + num6).ToString("F2")
				});
				((Worksheet)this.workBook.Worksheets[1]).Visible=0;
				i = 1;
				while (i <= this.workBook.Sheets.Count)
				{
					if (i > 1)
					{
						this.workSheet = (Worksheet)this.workBook.Worksheets[i];
						this.workSheet.Cells[nRowCountOfPage + 7 + 2, 15]= string.Concat(new string[]
						{
							"第",
							(i - 1).ToString(),
							"页/共",
							(this.workBook.Sheets.Count - 1).ToString(),
							"页"
						});
						string a2 = ((Range)this.workSheet.Cells[8, 1]).Text.ToString();
						string text4 = ((Range)this.workSheet.Cells[8, 2]).Text.ToString();
						string text5 = ((Range)this.workSheet.Cells[8, 3]).Text.ToString();
						int num4 = 0;
						int num7 = 8;
						if (((Range)this.workSheet.Cells[num7, 1]).Text.ToString() == "【类型】")
						{
							text4 = ((Range)this.workSheet.Cells[num7 + 1, 2]).Text.ToString();
							text5 = ((Range)this.workSheet.Cells[num7 + 1, 3]).Text.ToString();
							num7 = 9;
						}
						if (((Range)this.workSheet.Cells[num7, 1]).Text.ToString() == "·")
						{
							text4 = ((Range)this.workSheet.Cells[10, 2]).Text.ToString();
							text5 = ((Range)this.workSheet.Cells[10, 3]).Text.ToString();
							if (((Range)this.workSheet.Cells[10, 4]).Text.ToString() == "")
							{
								goto IL_2EAC;
							}
							num7 = 10;
						}
						for (int j = num7; j <= nRowCountOfPage + 7; j++)
						{
							if (((Range)this.workSheet.Cells[j, 2]).Text.ToString() == text4 && ((Range)this.workSheet.Cells[j, 3]).Text.ToString() == text5)
							{
								int num8 = j;
								num4 += Convert.ToInt32(((Range)this.workSheet.Cells[j, 4]).Text.ToString());
								if (num8 == nRowCountOfPage + 7)
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 2], this.workSheet.Cells[num8, 2]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text4);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 3], this.workSheet.Cells[num8, 3]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text5);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 4], this.workSheet.Cells[num8, 4]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(num4);
								}
							}
							else
							{
								int num8 = j - 1;
								a2 = ((Range)this.workSheet.Cells[j - 1, 1]).Text.ToString();
								if (a2 != "·" && a2 != "【类型】")
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 2], this.workSheet.Cells[num8, 2]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text4);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 3], this.workSheet.Cells[num8, 3]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text5);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num7, 4], this.workSheet.Cells[num8, 4]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(num4);
								}
								num7 = j;
								text4 = ((Range)this.workSheet.Cells[j, 2]).Text.ToString();
								text5 = ((Range)this.workSheet.Cells[j, 3]).Text.ToString();
								if (Regex.IsMatch(((Range)this.workSheet.Cells[j, 4]).Text.ToString(), "^[0-9]{1,}$"))
								{
									num4 = Convert.ToInt32(((Range)this.workSheet.Cells[j, 4]).Text.ToString());
								}
								if (text4 == "" && text5 == "")
								{
									break;
								}
							}
						}
						string a3 = ((Range)this.workSheet.Cells[8, 1]).Text.ToString();
						string text6 = ((Range)this.workSheet.Cells[8, 11]).Text.ToString();
						string text7 = ((Range)this.workSheet.Cells[8, 12]).Text.ToString();
						int num9 = 0;
						int num10 = 8;
						if (((Range)this.workSheet.Cells[num10, 1]).Text.ToString() == "【类型】")
						{
							text6 = ((Range)this.workSheet.Cells[num10 + 1, 11]).Text.ToString();
							text7 = ((Range)this.workSheet.Cells[num10 + 1, 12]).Text.ToString();
							num10 = 9;
						}
						if (((Range)this.workSheet.Cells[num10, 1]).Text.ToString() == "·")
						{
							text6 = ((Range)this.workSheet.Cells[10, 11]).Text.ToString();
							text7 = ((Range)this.workSheet.Cells[10, 12]).Text.ToString();
							if (((Range)this.workSheet.Cells[10, 13]).Text.ToString() == "")
							{
								goto IL_2EAC;
							}
							num10 = 10;
						}
						for (int j = num10; j <= nRowCountOfPage + 7; j++)
						{
							if (((Range)this.workSheet.Cells[j, 11]).Text.ToString() == text6 && ((Range)this.workSheet.Cells[j, 12]).Text.ToString() == text7)
							{
								int num11 = j;
								if (Regex.IsMatch(((Range)this.workSheet.Cells[j, 13]).Text.ToString(), "^[0-9]{1,}$"))
								{
									num9 += Convert.ToInt32(((Range)this.workSheet.Cells[j, 13]).Text.ToString());
								}
								if (num11 == nRowCountOfPage + 7)
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 11], this.workSheet.Cells[num11, 11]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text6);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 12], this.workSheet.Cells[num11, 12]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text7);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 13], this.workSheet.Cells[num11, 13]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(num9);
								}
							}
							else
							{
								int num11 = j - 1;
								a3 = ((Range)this.workSheet.Cells[j - 1, 1]).Text.ToString();
								if (a3 != "·" && a3 != "【类型】")
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 11], this.workSheet.Cells[num11, 11]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text6);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 12], this.workSheet.Cells[num11, 12]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text7);
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num10, 13], this.workSheet.Cells[num11, 13]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(num9);
								}
								num10 = j;
								text6 = ((Range)this.workSheet.Cells[j, 11]).Text.ToString();
								text7 = ((Range)this.workSheet.Cells[j, 12]).Text.ToString();
								if (Regex.IsMatch(((Range)this.workSheet.Cells[j, 13]).Text.ToString(), "^[0-9]{1,}$"))
								{
									num9 = Convert.ToInt32(((Range)this.workSheet.Cells[j, 13]).Text.ToString());
								}
								if (text6 == "" && text7 == "" && ((Range)this.workSheet.Cells[j, 2]).Text.ToString() == "" && ((Range)this.workSheet.Cells[j, 3]).Text.ToString() == "")
								{
									break;
								}
								if (((Range)this.workSheet.Cells[j + 1, 11]).Text.ToString() == "" && ((Range)this.workSheet.Cells[j + 1, 12]).Text.ToString() == "" && ((Range)this.workSheet.Cells[j + 1, 2]).Text.ToString() == "" && ((Range)this.workSheet.Cells[j + 1, 3]).Text.ToString() == "")
								{
									break;
								}
							}
							if (text6 == "" && text7 == "" && ((Range)this.workSheet.Cells[j, 2]).Text.ToString() == "" && ((Range)this.workSheet.Cells[j, 3]).Text.ToString() == "")
							{
								break;
							}
						}
					}
					IL_2EAC:
					i++;
					continue;
					goto IL_2EAC;
				}
				num2++;
				for (int j = num2; j <= nRowCountOfPage + 7; j++)
				{
					this.range = (Range)this.workSheet.Rows[num2, this.missing];
					this.range.Delete(-4121);
				}
				this.workBook.Save();
			}
			catch (Exception ex)
			{
				this.workBook.Save();
				throw ex;
			}
		}

		private void MakeOrderDataToExcel_4(DataSet dsOrderItem, string sFlowcardCode, string sCompanyName, string sProjectName, string sSpeakForDate, string sDeliveryDate, string sLinkman, string sPhone, string sAddress, string sRemark, string sOperatorName, string sSalesperson, string sYaoqiu, int nRowCountOfPage, int nRowHight)
		{
			int count = dsOrderItem.Tables[0].Rows.Count;
			try
			{
				int num = 1;
				int num2 = 7;
				int num3 = 0;
				decimal num4 = 0m;
				decimal d = 0m;
				this.workSheet = (Worksheet)workBook.Worksheets[this.workBook.Worksheets.Count];
				this.range = (Range)this.workSheet.Rows[8, this.missing];
				for (int i = 1; i < nRowCountOfPage; i++)
				{
					this.range.Insert(-4121, 1);
				}
				this.range = (Range)this.workSheet.Rows[nRowCountOfPage + 7, this.missing];
				for (int i = 1; i < nRowCountOfPage; i++)
				{
					Range range = (Range)this.workSheet.Rows[i + 7, this.missing];
					this.range.Copy(range);
				}
				((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
				this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
				this.workSheet.Activate();
				this.workSheet.Cells[4, 8]= "流程单号：" + sFlowcardCode;
				this.workSheet.Cells[4, 1]= string.Concat(new string[]
				{
					"客户名称：",
					sCompanyName,
					"(",
					sProjectName,
					")"
				});
				this.workSheet.Cells[5, 1]= "订货时间：" + sSpeakForDate;
				this.workSheet.Cells[5, 8]= "交货时间：" + sDeliveryDate;
				this.workSheet.Cells[6, 1]= "备    注：" + sRemark;
				this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
				this.range.Value2=(this.range.Text.ToString().Replace("?", sOperatorName));
				this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 7];
				this.range.Value2=(this.range.Text.ToString().Replace("?", sSalesperson));
				this.workSheet.Name=("页-" + (this.workSheet.Index - 1).ToString());
				for (int i = 0; i < count; i++)
				{
					num2++;
					if (num2 > nRowCountOfPage + 7)
					{
						num++;
						((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
						this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
						this.workSheet.Activate();
						this.workSheet.Cells[4, 8]= "流程单号：" + sFlowcardCode;
						this.workSheet.Cells[4, 1]= string.Concat(new string[]
						{
							"客户名称：",
							sCompanyName,
							"(",
							sProjectName,
							")"
						});
						this.workSheet.Cells[5, 1]= "订货时间：" + sSpeakForDate;
						this.workSheet.Cells[5, 8]= "交货时间：" + sDeliveryDate;
						this.workSheet.Cells[6, 1]= "备    注：" + sRemark;
						this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
						this.range.Value2=(this.range.Text.ToString().Replace("?", sOperatorName));
						this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 7];
						this.range.Value2=(this.range.Text.ToString().Replace("?", sSalesperson));
						this.workSheet.Name=("页-" + (this.workSheet.Index - 1).ToString());
						num2 = 8;
					}
					decimal d2 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["宽"]);
					decimal d3 = Convert.ToDecimal(dsOrderItem.Tables[0].Rows[i]["高"]);
					int num5 = Convert.ToInt32(dsOrderItem.Tables[0].Rows[i]["产品数量"]);
					decimal d4 = Convert.ToDecimal((d2 * d3 / 1000000m).ToString("F4")) * num5;
					decimal d5 = Convert.ToDecimal(((d2 + d3) * 2m / 1000m).ToString("F4")) * num5;
					num3 += num5;
					num4 += d4;
					d += d5;
					this.workSheet.Cells[num2, 1]= dsOrderItem.Tables[0].Rows[i]["产品类型"].ToString();
					this.workSheet.Cells[num2, 3]= dsOrderItem.Tables[0].Rows[i]["产品编号"].ToString();
					string text = dsOrderItem.Tables[0].Rows[i]["宽(短边)"].ToString();
					string text2 = dsOrderItem.Tables[0].Rows[i]["高(短边)"].ToString();
					this.workSheet.Cells[num2, 4]= d2.ToString() + ((text == "") ? "" : ("/" + text));
					this.workSheet.Cells[num2, 5]= d3.ToString() + ((text2 == "") ? "" : ("/" + text2));
					this.workSheet.Cells[num2, 6]= dsOrderItem.Tables[0].Rows[i]["类型单位"].ToString();
					this.workSheet.Cells[num2, 7]= num5.ToString();
					this.workSheet.Cells[num2, 8]= d4.ToString();
					this.workSheet.Cells[num2, 9]= d5.ToString("F4");
					this.workSheet.Cells[num2, 10]= Convert.ToDouble(dsOrderItem.Tables[0].Rows[i]["产品价格"].ToString());
					this.workSheet.Cells[num2, 11]= dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() + ((dsOrderItem.Tables[0].Rows[i]["产品备注"].ToString() != "" && dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString() != "") ? ("/" + dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString()) : dsOrderItem.Tables[0].Rows[i]["产品工艺"].ToString());
					this.workSheet.Cells[num2, 12]= dsOrderItem.Tables[0].Rows[i]["产品ID"].ToString().Split(new char[]
					{
						'-'
					}).GetValue(1).ToString();
					string a = dsOrderItem.Tables[0].Rows[i][1].ToString();
					if (i == count - 1)
					{
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[4, 8]= "流程单号：" + sFlowcardCode;
							this.workSheet.Cells[4, 1]= string.Concat(new string[]
							{
								"客户名称：",
								sCompanyName,
								"(",
								sProjectName,
								")"
							});
							this.workSheet.Cells[5, 1]= "订货时间：" + sSpeakForDate;
							this.workSheet.Cells[5, 8]= "交货时间：" + sDeliveryDate;
							this.workSheet.Cells[6, 1]= "备    注：" + sRemark;
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=(this.range.Text.ToString().Replace("?", sOperatorName));
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 7];
							this.range.Value2=(this.range.Text.ToString().Replace("?", sSalesperson));
							this.workSheet.Name=("页-" + (this.workSheet.Index - 1).ToString());
							num2 = 8;
						}
						this.workSheet.Cells[num2, 1]= "·";
						this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 3], this.workSheet.Cells[num2, 6]);
						this.range.ClearContents();
						this.range.MergeCells=true;
						this.workSheet.Cells[num2, 3]= " 小计 ";
						this.workSheet.Cells[num2, 7]= num3.ToString() + ".";
						this.workSheet.Cells[num2, 8]= num4;
						this.workSheet.Cells[num2, 9]= d.ToString("F3");
						num3 = 0;
						d = 0m;
						num4 = 0m;
					}
					else if (a != dsOrderItem.Tables[0].Rows[i + 1][1].ToString())
					{
						num2++;
						if (num2 > nRowCountOfPage + 7)
						{
							num++;
							((Worksheet)this.workBook.Worksheets[1]).Copy(this.missing, (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count]);
							this.workSheet = (Worksheet)this.workBook.Worksheets[this.workBook.Worksheets.Count];
							this.workSheet.Activate();
							this.workSheet.Cells[4, 8]= "流程单号：" + sFlowcardCode;
							this.workSheet.Cells[4, 1]= string.Concat(new string[]
							{
								"客户名称：",
								sCompanyName,
								"(",
								sProjectName,
								")"
							});
							this.workSheet.Cells[5, 1]= "订货时间：" + sSpeakForDate;
							this.workSheet.Cells[5, 8]= "交货时间：" + sDeliveryDate;
							this.workSheet.Cells[6, 1]= "备    注：" + sRemark;
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 1];
							this.range.Value2=(this.range.Text.ToString().Replace("?", sOperatorName));
							this.range = (Range)this.workSheet.Cells[nRowCountOfPage + 7 + 2, 7];
							this.range.Value2=(this.range.Text.ToString().Replace("?", sSalesperson));
							this.workSheet.Name=("页-" + (this.workSheet.Index - 1).ToString());
							num2 = 8;
						}
						this.workSheet.Cells[num2, 1]= "·";
						this.range = this.workSheet.get_Range(this.workSheet.Cells[num2, 3], this.workSheet.Cells[num2, 6]);
						this.range.ClearContents();
						this.range.MergeCells=true;
						this.workSheet.Cells[num2, 3]= " 小计 ";
						this.workSheet.Cells[num2, 7]= num3.ToString() + ".";
						this.workSheet.Cells[num2, 8]= num4;
						this.workSheet.Cells[num2, 9]= d.ToString("F3");
						num3 = 0;
						d = 0m;
						num4 = 0m;
					}
				}
				((Worksheet)this.workBook.Worksheets[1]).Visible=(0);
				for (int i = 1; i <= this.workBook.Sheets.Count; i++)
				{
					if (i > 1)
					{
						this.workSheet = (Worksheet)this.workBook.Worksheets[i];
						this.workSheet.Cells[3, 11]= string.Concat(new string[]
						{
							"第",
							(i - 1).ToString(),
							"页/共",
							(this.workBook.Sheets.Count - 1).ToString(),
							"页"
						});
						string text3 = ((Range)this.workSheet.Cells[8, 1]).Text.ToString();
						int num6 = 8;
						for (int j = 8; j <= nRowCountOfPage + 7; j++)
						{
							if (((Range)this.workSheet.Cells[j, 1]).Text.ToString() == text3)
							{
								int num7 = j;
								if (num7 == nRowCountOfPage + 7)
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num6, 1], this.workSheet.Cells[num7, 2]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text3);
									this.range.WrapText=true;
								}
							}
							else
							{
								int num7 = j - 1;
								if (text3 != "·" && text3.IndexOf("★") < 0)
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num6, 1], this.workSheet.Cells[num7, 2]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									this.range.Value2=(text3);
									this.range.WrapText=true;
								}
								num6 = j;
								text3 = ((Range)this.workSheet.Cells[j, 1]).Text.ToString();
								if (text3 == "")
								{
									this.range = this.workSheet.get_Range(this.workSheet.Cells[num6, 1], this.workSheet.Cells[nRowCountOfPage + 7, 10]);
									this.range.ClearContents();
									this.range.MergeCells=true;
									break;
								}
							}
						}
					}
				}
				num2++;
				for (int j = num2; j <= nRowCountOfPage + 7; j++)
				{
					this.range = (Range)this.workSheet.Rows[num2, this.missing];
					this.range.Delete(-4121);
				}
				this.workBook.Save();
			}
			catch (Exception ex)
			{
				this.workBook.Save();
				throw ex;
			}
		}
	}
}
